<?php

namespace App\Containers\AppSection\Profile\Actions;

use App\Containers\AppSection\File\Models\File;
use App\Containers\AppSection\File\Tasks\CreateFileTask;
use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Containers\AppSection\Profile\Tasks\UpdateProfileTask;
use App\Containers\AppSection\Profile\UI\API\Requests\ChangeProfileAvatarRequest;
use App\Ship\Parents\Actions\Action;

class ChangeProfileAvatarAction extends Action
{
    public function run(ChangeProfileAvatarRequest $request): File
    {
        $file = app(CreateFileTask::class)->run($request->avatar, 'avatar', $request->profile()->id);
        app(UpdateProfileTask::class)->run($request->profile()->id, ['avatar_id' => $file->id]);


        app(CreateLogTask::class)->run($request->profile()->id, 'Смена аватарки', 'profile');

        return $file;
    }
}
